<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
    <style>
        div{
            position: absolute;
            left: 0;
            width: 100px;
            height: 100px;
            background-color: pink;
        }
        span{
            display: block;
            position: absolute;
            left: 0;
            top: 200px;
            width: 150px;
            height: 150px;
            background-color: purple;
        }
    </style>
</head>
<body>
<div></div>
<span>夏雨荷</span>
<script>
   //简单函数封装 obj目标对象 target目标位置
   function animate(obj,target) {
       var timer = setInterval(function () {
           if (obj.offsetLeft >= target){
               //停止动画 本质是停止定时器
               clearInterval(timer);
           }
           obj.style.left = obj.offsetLeft + 1 + 'px';
       },30)
   }

   var div = document.querySelector('div');
   var span = document.querySelector('span');
   //调用函数
   animate(div,100);
   animate(span,200);
</script>
</body>
</html>
